package com.cjb.cloudsecurity.userMsg.service;

import com.cjb.cloudsecurity.userMsg.entity.UserDetail;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * All rights Reserved, Designed By  chenjinbin
 *
 * @author chenjinbin
 * @Project: fjbd_cjb_bs
 * @Package com.cjb.cloudsecurity.userMsg.service
 * @title SecurityUserService
 * @Description
 * @email
 * @date 2023-08-30 14:45
 * @since JDK 1.8
 */
public interface SecurityUserService {
    /**
     * 获取用户信息
     *
     * @param
     * @return
     * @author chenjinbin
     * @email 2213859123@qq.com
     * @date 2023-07-12 9:10
     */
    static UserDetail getUser() {
        UserDetail user;
        try {
            user = (UserDetail) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        } catch (Exception e) {
            return null;
        }

        return user;
    }

    /**
     * 获取租户的id
     *
     * @param
     * @return
     * @author chenjinbin
     * @email 2213859123@qq.com
     * @date 2023-07-12 9:10
     */
    static Long getUserId() {
        UserDetail user = getUser();
        if (user == null) {
            return null;
        }

        return user.getId();
    }
}
